import Sequelize from 'sequelize';
import baseDao from '../lib/baseDao.js'; // 数据库操作

const Modal = baseDao.sequelize.define('t_user', {
  // 属性
  id: {
    type: Sequelize.INTEGER,
    primaryKey: true, // 主键
    autoIncrement: true, // 自增
    allowNull: true,
    validate: {
      len: [1, 50]
    }
  },
  username: { // 用户名不唯一，手机号唯一
    type: Sequelize.STRING,
    allowNull: true,
    validate: {
      len: [0, 20]
    },
    comment: '用户名'
  },
  password: {
    type: Sequelize.STRING,
    allowNull: true,
    validate: {
      len: [0, 20]
    },
    comment: '密码'
  },
  openId: {
    type: Sequelize.STRING,
    unique: true, // 唯一约束
    allowNull: true,
    validate: {
      len: [0, 50]
    },
    comment: '公众平台openId'
  },
  unionId: {
    type: Sequelize.STRING,
    unique: true, // 唯一约束
    allowNull: true,
    validate: {
      len: [0, 50]
    },
    comment: '开放平台unionId'
  },
  nickName: {
    type: Sequelize.STRING,
    allowNull: true,
    validate: {
      len: [0, 50]
    },
    comment: '用户名'
  },
  mobile: {
    type: Sequelize.STRING,
    allowNull: true,
    unique: true, // 唯一约束
    validate: {
      len: [11, 11]
    },
    comment: '手机号'
  },
  email: {
    type: Sequelize.STRING,
    allowNull: true,
    validate: {
      len: [0, 50]
    },
    comment: '邮箱号'
  },
  city: {
    type: Sequelize.STRING,
    allowNull: true,
    validate: {
      len: [0, 50]
    },
    comment: '城市'
  },
  country: {
    type: Sequelize.STRING,
    allowNull: true,
    validate: {
      len: [0, 50]
    },
    comment: '国家'
  },
  gender: {
    type: Sequelize.INTEGER,
    allowNull: true,
    validate: {
      len: [0, 5]
    },
    comment: '性别，0未知1男2女'
  },
  level: {
    type: Sequelize.INTEGER,
    allowNull: true,
    validate: {
      len: [0, 5]
    },
    defaultValue: 1,
    comment: '客户等级,最低为1'
  },
  gold: {
    type: Sequelize.INTEGER,
    allowNull: true,
    validate: {
      len: [0, 10]
    },
    defaultValue: 0,
    validate: { min: 0 },
    comment: '用户余额'
  },
  tradeParentId: {
    type: Sequelize.STRING,
    allowNull: true,
    unique: true, // 唯一约束
    validate: {
      len: [0, 6]
    },
    comment: '截取订单号后6位作为用户淘宝ID'
  },
  avatarUrl: {
    type: Sequelize.STRING,
    allowNull: true,
    validate: {
      len: [0, 200]
    },
    comment: '用户头像'
  },
  language: {
    type: Sequelize.STRING,
    allowNull: true,
    validate: {
      len: [0, 50]
    },
    comment: '用户语言'
  },
}, {
    // 参数
  });

//向外暴露
export default {
  Modal,
}